package leetcode;

public class LeetCode14 {

    public static void main(String[] args) {
        LeetCode14 leetCode14=new LeetCode14();
        leetCode14.longestCommonPrefix(new String[]{"flower","flow","flight"});
    }
    public String longestCommonPrefix(String[] strs) {
        if (strs.length == 0)
            return "";
        int index = 0;
        char tmp;
        StringBuffer result = new StringBuffer("");
        label:
        while (index < strs[0].length()) {
            tmp = strs[0].charAt(index);
            for (int i = 1; i < strs.length; i++) {
                if (strs[i].length() <= index || tmp != strs[i].charAt(index))
                    break label;
            }
            index++;
            result.append(tmp);
        }
        return result.toString();
    }
//------------------------------------------------------------------
}
